//
//  HELSpecialistlistVC.m
//  NursingAssociation
//
//  Created by wsj2015 on 2017/3/13.
//  Copyright © 2017年 wsj2015. All rights reserved.
//

#import "HELSpecialistlistVC.h"
#import "HELSecoalistListCell.h"
#import "HELSecoalistModel.h"
#import "HELSepcialistDetailVC.h"
@interface HELSpecialistlistVC ()

@end

@implementation HELSpecialistlistVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

-(void)configUI{
  self.title  =@"我的专家";
  [self.view addSubview:self.tableView];
  [self.tableView registerNib:[UINib nibWithNibName:@"HELSecoalistListCell" bundle:nil] forCellReuseIdentifier:@"HELSecoalistListCell"];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    weakSelf_define;
  [self.tableView wsj_HeaderRefreshBlock:^{
      [weakSelf getMySepcialist:YES];
  }];
  [self.tableView wsj_FooterRefreshBlock:^{
      [weakSelf getMySepcialist:NO];
  }];
  [self getMySepcialist:YES];
  
}

- (void)getMySepcialist:(BOOL)isRecover{
    static NSUInteger page = 1;
    if (isRecover) {
        page =1;
    }else{
        page ++;
    }
    
    NSMutableDictionary *params =[NSMutableDictionary dictionary];
    params[@"page"] = @(page);
    params[@"rows"] = @(15);
    
 
    
    
    weakSelf_define;
    self.tableView.loading = YES;
    [[HELNetworkManager sharedMg] POST:helSpecialist parameters:params success:^(id responseObject) {
        
        [weakSelf.tableView.header endRefreshing];
        [weakSelf.tableView.footer endRefreshing];
        weakSelf.tableView.loading = NO;
        if ([responseObject[@"data"] isKindOfClass:[NSDictionary class]]) {
            
            if (isRecover) {
                [weakSelf.dataArray removeAllObjects];
            }
            NSInteger totalPage = 0;
            if ([responseObject[@"data"][@"totalPage"] isKindOfClass:[NSNull class]]) {
                
            }else{
                totalPage =[responseObject[@"data"][@"totalPage"] integerValue];
            }
            
            NSInteger currentPage = [responseObject[@"data"][@"page"] integerValue];
            if (currentPage>=totalPage) {
                [weakSelf.tableView.footer noticeNoMoreData];
            }else{
                [weakSelf.tableView.footer resetNoMoreData];
            }
            
            [weakSelf.dataArray addObjectsFromArray:[HELSecoalistModel mj_objectArrayWithKeyValuesArray:responseObject[@"data"][@"data"]]];
            
            [weakSelf.tableView reloadData];
            
        }
        
        
    } failure:^(NSString *err) {
        [weakSelf.tableView.header endRefreshing];
        [weakSelf.tableView.footer endRefreshing];
        weakSelf.tableView.loading = NO;
    }];
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
 
//    return 2;
    return self.dataArray.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return  126;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    HELSecoalistListCell  *cell = [tableView dequeueReusableCellWithIdentifier:@"HELSecoalistListCell"];
    cell.model = self.dataArray[indexPath.row];
 
    return cell;
    
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    HELSecoalistModel *model = self.dataArray[indexPath.row];
    HELSepcialistDetailVC *vc =[HELSepcialistDetailVC new];
    vc.specialistId = [model.id integerValue];
//
    [self.navigationController pushViewController:vc animated:YES];
    
}



@end
